package com.zmn.plat.admin.controller.orderconfig.serviceaudit;

import java.util.List;
import java.util.Optional;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.zmn.plat.model.entity.orderconfig.serviceaudit.OrderServiceAuditReason;
import com.zmn.plat.model.entity.orderconfig.serviceaudit.OrderServiceAuditReasonQuery;

/**
 * @author tanbiao
 * @description：订单配置取消缘由
 * @since 2019/10/21 16:49
 * @modifier
 **/
@Controller
@RequestMapping("/orderconfig/serviceAuditReason/")
public class OrderServiceAuditReasonListController extends OrderServiceAuditReasonBaseController {
    private Logger logger = LoggerFactory.getLogger(OrderServiceAuditReasonListController.class);

    /**
     * 描述: 取消缘由列表
     *
     * @param query
     *            查询实体
     * @return ModelAndView
     * @author tanbiao
     * @since 15:38 2019/10/22
     */
    @SuppressWarnings("Duplicates")
    @RequestMapping(value = "list")
    @RequiresPermissions("/orderconfig/serviceAuditReason/list.action")
    public ModelAndView list(@ModelAttribute OrderServiceAuditReasonQuery query) {
        ModelAndView mav = new ModelAndView("orderconfig/serviceaudit/list");
        int count = orderServiceAuditReasonService.countByQuery(query);
        query.setTotalCount(count);
        List<OrderServiceAuditReason> items = orderServiceAuditReasonService.listPageByQuery(query);
        mav.addObject("items", items);
        mav.addObject("vo", query);
        mav.addObject("bizTypeList", com.zmn.plat.common.dictionary.ProductDict.listBizType());
        return mav;
    }

    /**
     * 功能描述 ：详情页面
     *
     * @param id
     * @return org.springframework.web.servlet.ModelAndView
     * @author tanbiao
     * @since 2019/10/22
     * @modifier
     */
    @RequestMapping(value = "detail")
    @RequiresPermissions("/orderconfig/serviceAuditReason/detail.action")
    public ModelAndView detail(@RequestParam(value = "id", defaultValue = "0") Integer id) {
        ModelAndView mav = new ModelAndView("orderconfig/serviceaudit/detail");
        OrderServiceAuditReason orderAuditReason = new OrderServiceAuditReason();
        if (id == 0) {
            orderAuditReason = new OrderServiceAuditReason();
        } else {
            orderAuditReason = Optional.ofNullable(orderServiceAuditReasonService.findByKey(id)).orElse(orderAuditReason);
        }
        if (orderAuditReason.getSort() == null) {
            Integer sort = orderServiceAuditReasonService.findMaxSort();
            sort = sort == null ? 1 : sort + 1;
            orderAuditReason.setSort(sort);
        }
        mav.addObject("reason", orderAuditReason);
        mav.addObject("bizTypeList", com.zmn.plat.common.dictionary.ProductDict.listBizType());
        return mav;
    }
}
